import com.example.bean.Product;
import com.example.bean.Student;
import com.example.ioc.ClassPathXmlApplicationContext;
import org.dom4j.DocumentException;
import org.junit.Test;

import java.lang.reflect.InvocationTargetException;

public class IocContainerTest {
    @Test
    public void testIocContainer() throws DocumentException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        // 初始化IOC容器
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");

        // 通过id获取Bean
        Product product = (Product) context.getBean("product1");
        System.out.println("通过id获取的Product: " + product);

        // 通过类型获取Bean
        Student student = context.getBean(Student.class);
        System.out.println("通过类型获取的Student: " + student);
    }
}
